<extend name="Public/base" />
<block name="style">
    <link rel="stylesheet" type="text/css" href="__STATIC__/bootstrap3/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/FlatUI/css/flat-ui.min.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/style/style.css">
</block>
<block name="body">

    <body>
        <div class="main">
            <div class="paper">
                <div class="toolbar">
                    <span class="title">业务管理</span>
                </div>
                <div class="divider"></div>
                <div class="body">
                    <div class="serch_area">
                        <form role="form" method="get">
                            <div class="row">
                                <div class="col-lg-2">
                                    <div class="form-group">
                                        <label class="sr-only" for="exampleInput">账号</label>
                                        <input type="text" class="form-control" placeholder="账号" name="zh">
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <div class="form-group">
                                        <label class="sr-only" for="exampleInput">链接</label>
                                        <input type="text" class="form-control" placeholder="链接" name="lj">
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <div class="input-group form-group ">
                                        <span class="input-group-addon">下线开始</span>
                                        <input type="text" class="form-control find_date start" name="xxsj_start" placeholder="开始时间" />
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <div class="input-group form-group ">
                                        <input type="text" class="form-control find_date end" name="xxsj_end" placeholder="结束时间" />
                                        <span class="input-group-addon">下线结束</span>
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <div class="input-group form-group">
                                        <span class="input-group-addon">上线开始</span>
                                        <input type="text" class="form-control form_date start" name="sxsj_start" placeholder="开始时间" />
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <div class="input-group form-group">
                                        <input type="text" class="form-control form_date end" name="sxsj_end" placeholder="结束时间" />
                                        <span class="input-group-addon">上线结束</span>
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <div class="form-group ">
                                        <select data-toggle="select" class="form-control select select-primary" name="xm">
                                            <option value="">所有项目</option>
                                            <volist name="xms" id="xm">
                                                <option value="{$xm.name}">{$xm.name}</option>
                                            </volist>
                                    </select>
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <div class="form-group ">
                                        <select data-toggle="select" class="form-control select select-primary" name="yw">
                                            <option value="">所有业务</option>
                                           <volist name="yws" id="yw">
                                                <option value="{$yw.name}">{$yw.name}</option>
                                            </volist>
                                    </select>
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <div class="form-group ">
                                        <select data-toggle="select" class="form-control select select-primary" name="sy">
                                                <option value="">所有上游</option>
                                               <volist name="sys" id="sy">
                                                    <option value="{$sy.name}">{$sy.name}</option>
                                                </volist>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <div class="form-group ">
                                        <select data-toggle="select" class="form-control select select-primary" name="xy">
                                                <option value="">所有下游</option>
                                                <volist name="xys" id="xy">
                                                    <option value="{$xy.name}">{$xy.name}</option>
                                                </volist>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <div class="form-group ">
                                        <select data-toggle="select" class="form-control select select-primary" name="qy">
                                                <option value="">所有区域</option>
                                                <volist name="qys" id="qy">
                                                    <option value="{$qy.name}">{$qy.name}</option>
                                                </volist>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <div class="form-group ">
                                        <select data-toggle="select" class="form-control select select-primary" name="zt">
                                                <option value="">所有状态</option>
                                                <option value="上线">上线</option>
                                                <option value="下线">下线</option>
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <button type="submit" class="btn btn-embossed btn-primary form-group">
                            查询
                            </button>
                            <button type="button" class="btn btn-embossed btn-info form-group" data-toggle="modal" data-target="#addModal">
                                新增
                            </button>
                            <a href="{:U('csv_export',array('csv_name'=>'所有项目数据'))}" class="btn btn-embossed btn-info form-group">
                                csv导出
                            </a>
                        </form>
                    </div>
                    <div class="divider"></div>
                    <div class="table_area content-block table-responsive">
                        <table class="table table-striped table-bordered">
                            <thead>
                                <tr>
                                    <th>项目</th>
                                    <th>业务</th>
                                    <th>账号</th>
                                    <th>链接</th>
                                    <th>状态</th>
                                    <th>上游</th>
                                    <th>上线时间</th>
                                    <th>下线时间</th>
                                    <th>区域</th>
                                    <th>价格</th>
                                    <th>策略id</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <volist name="lists" id="list">
                                    <tr>
                                        <td>{$list.xm}</td>
                                        <td>{$list.yw}</td>
                                        <td>{$list.zh}</td>
                                        <td>
                                            <input class="tooltiptd form-control" type="text" value="{$list.lj}" data-toggle="tooltip" title="{$list.lj}" data-placement="top">
                                        </td>
                                        <eq name="list.zt" value="下线"><td style="color:red">{$list.zt}</td></eq>
                                        <neq name="list.zt" value="下线"><td>{$list.zt}</td></neq>
                                        <td>{$list.sy}</td>
                                        <td>{$list.sxsj}</td>
                                        <td>{$list.xxsj}</td>
                                        <td>{$list.qy}</td>
                                        <td>{$list.jg}</td>
                                        <td>{$list.sids}</td>
                                        <td class="actions">
                                            <a type="button" class="btn btn-info btn-sm btn-embossed updatebtn" data-id="{$list.id}">编辑</a>
                                            <a type="button" class="btn btn-inverse btn-sm btn-embossed" href="{:U('Bb/lst',array('xm_id'=>$list['xm_id'],'xm'=>$list['xm'],'yw'=>$list['yw'],'zh'=>$list['zh'],'csv_name'=>$list['xm'].$list['yw'].$list['zh'].'报表'))}">报表</a>
                                            <a type="button" class="btn btn-inverse btn-sm btn-embossed" href="{:U('Cdata/lst',array('sids'=>$list['sids'],'csv_name'=>$list['xm'].$list['yw'].$list['zh'].'业务数据'))}">业务数据</a>
                                            <a type="button" class="btn btn-danger btn-sm btn-embossed" href="{:U('del',array('id'=>$list['id']))}">删除</a>
                                        </td>
                                    </tr>
                                </volist>
                            </tbody>
                        </table>
                        <div class="page">
                            {$_page}
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- Modal -->
        <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog modal-lg" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h6 class="modal-title" id="myModalLabel">新增业务</h6>
                    </div>
                    <div class="modal-body">
                        <form id="add_form" class="form-horizontal public_form" action="{:U('add')}" method="post">
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">项目名称</label>
                                <div class="col-lg-4">
                                    <select data-toggle="select" class="form-control select select-primary" name="xm">
                                        <optgroup label="项目名称">
                                            <volist name="xms" id="xm">
                                            <option value="{$xm.name}">{$xm.name}</option>
                                        </volist>
                                        </optgroup>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">业务</label>
                                <div class="col-lg-4">
                                    <select data-toggle="select" class="form-control select select-primary" name="yw">
                                        <optgroup label="业务">
                                            <volist name="yws" id="yw">
                                            <option value="{$yw.name}">{$yw.name}</option>
                                        </volist>
                                        </optgroup>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">业务备注</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="yw_bz" placeholder="业务备注">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">价格</label>
                                <div class="col-lg-4">
                                    <input type="text" class="form-control" name="jg" placeholder="价格">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">价格备注</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="jg_bz" placeholder="价格">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">账号</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="zh" placeholder="账号">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">账号备注</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="zh_bz" placeholder="账号备注">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">链接</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="lj" placeholder="链接">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">链接备注</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="lj_bz" placeholder="链接备注">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">上线时间</label>
                                <div class="col-lg-4">
                                    <input type="text" class="form-control form_date" name="sxsj" data-date-format="yyyy-mm-dd" value="">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">下线时间</label>
                                <div class="col-lg-4">
                                    <input type="text" class="form-control form_date" name="xxsj" data-date-format="yyyy-mm-dd" value="">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">状态</label>
                                <div class="col-lg-4">
                                    <select data-toggle="select" class="form-control select select-primary" name="zt">
                                    <optgroup label="状态">
                                        <option value="上线">上线</option>
                                        <option value="下线">下线</option>
                                    </optgroup>
                                </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">上游</label>
                                <div class="col-lg-4">
                                    <select data-toggle="select" class="form-control select select-primary" name="sy">
                                    <optgroup label="上游">
                                        <volist name="sys" id="sy">
                                            <option value="{$sy.name}">{$sy.name}</option>
                                        </volist>
                                    </optgroup>
                                </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">下游</label>
                                <div class="col-lg-4">
                                    <select data-toggle="select" class="form-control select select-primary" name="xy">
                                    <optgroup label="下游">
                                        <volist name="xys" id="xy">
                                            <option value="{$xy.name}">{$xy.name}</option>
                                        </volist>
                                    </optgroup>
                                </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">区域</label>
                                <div class="col-lg-4">
                                    <select data-toggle="select" class="form-control select select-primary" name="qy">
                                        <optgroup label="区域">
                                            <volist name="qys" id="qy">
                                            <option value="{$qy.name}">{$qy.name}</option>
                                        </volist>
                                        </optgroup>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">区域备注</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="qy_bz" placeholder="区域备注">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">策略id</label>
                                <div class="col-lg-8">
                                    <input name="sids" class="tagsinput form-control" data-role="tagsinput" value="" />
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default btn-embossed" data-dismiss="modal">关闭</button>
                        <button type="button" id="addbtn" class="btn btn-primary btn-embossed">保存</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- Modal -->
        <div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog modal-lg" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h6 class="modal-title" id="myModalLabel">编辑业务</h6>
                    </div>
                    <div class="modal-body">
                        <form id="update_form" class="form-horizontal public_form" action="{:U('edit')}" method="post">
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">项目名称</label>
                                <div class="col-lg-4">
                                    <select data-toggle="select" class="form-control select select-primary" name="xm">
                                        <optgroup label="项目名称">
                                            <volist name="xms" id="xm">
                                            <option value="{$xm.name}">{$xm.name}</option>
                                        </volist>
                                        </optgroup>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">业务</label>
                                <div class="col-lg-4">
                                    <select data-toggle="select" class="form-control select select-primary" name="yw">
                                        <optgroup label="业务">
                                            <volist name="yws" id="yw">
                                            <option value="{$yw.name}">{$yw.name}</option>
                                        </volist>
                                        </optgroup>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">业务备注</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="yw_bz" placeholder="业务备注">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">价格</label>
                                <div class="col-lg-4">
                                    <input type="text" class="form-control" name="jg" placeholder="价格">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">价格备注</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="jg_bz" placeholder="价格">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">账号</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="zh" placeholder="账号">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">账号备注</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="zh_bz" placeholder="账号备注">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">链接</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="lj" placeholder="链接">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">链接备注</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="lj_bz" placeholder="链接备注">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">上线时间</label>
                                <div class="col-lg-4">
                                    <input type="text" class="form-control form_date" name="sxsj" data-date-format="yyyy-mm-dd" value="">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">下线时间</label>
                                <div class="col-lg-4">
                                    <input type="text" class="form-control form_date" name="xxsj" data-date-format="yyyy-mm-dd" value="">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">状态</label>
                                <div class="col-lg-4">
                                    <select data-toggle="select" class="form-control select select-primary" name="zt">
                                    <optgroup label="状态">
                                        <option value="上线">上线</option>
                                        <option value="下线">下线</option>
                                    </optgroup>
                                </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">上游</label>
                                <div class="col-lg-4">
                                    <select data-toggle="select" class="form-control select select-primary" name="sy">
                                    <optgroup label="上游">
                                        <volist name="sys" id="sy">
                                            <option value="{$sy.name}">{$sy.name}</option>
                                        </volist>
                                    </optgroup>
                                </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">下游</label>
                                <div class="col-lg-4">
                                    <select data-toggle="select" class="form-control select select-primary" name="xy">
                                    <optgroup label="下游">
                                        <volist name="xys" id="xy">
                                            <option value="{$xy.name}">{$xy.name}</option>
                                        </volist>
                                    </optgroup>
                                </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">区域</label>
                                <div class="col-lg-4">
                                    <select data-toggle="select" class="form-control select select-primary" name="qy">
                                        <optgroup label="区域">
                                            <volist name="qys" id="qy">
                                            <option value="{$qy.name}">{$qy.name}</option>
                                        </volist>
                                        </optgroup>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">区域备注</label>
                                <div class="col-lg-8">
                                    <input type="text" class="form-control" name="qy_bz" placeholder="区域备注">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInput" class="col-lg-2 control-label">策略id</label>
                                <div class="col-lg-8">
                                    <input name="sids" class="tagsinput form-control" value="" />
                                </div>
                            </div>
                            <input type="hidden" class="form-control" name="id">
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default btn-embossed" data-dismiss="modal">关闭</button>
                        <button type="button" id="savetn" class="btn btn-primary btn-embossed">保存</button>
                    </div>
                </div>
            </div>
        </div>
    </body>
</block>
<block name="script">
    <script type="text/javascript" src="__STATIC__/FlatUI/js/flat-ui.min.js"></script>
    <script type="text/javascript" src="__STATIC__/FlatUI/js/application.js"></script>
    <script type="text/javascript" src="__STATIC__/bootstrapValidator.min.js"></script>
    <script type="text/javascript" src="__STATIC__/moment.js"></script>
    <script type="text/javascript" src="__STATIC__/validator.js"></script>
    <script>
        $(function () {
            var inputval;
            $("input").change(function () {
                var _adrobj = $(this).val().replace(/\"/g,"'");
                $(this).val(_adrobj)
            })
            $(".tooltiptd").hover(function () {
                $(this).select();
                inputval = $(this).val()
            }, function () {
                $(this).val(inputval)
                $(this).blur()
            })
            //下拉框搜索插件加载
            $('select[name="yw"]').select2({
                dropdownCssClass: 'select-inverse-dropdown show-select-search'
            });
            $('select[name="xm"]').select2({
                dropdownCssClass: 'select-inverse-dropdown show-select-search'
            });
            $('select[name="sy"]').select2({
                dropdownCssClass: 'select-inverse-dropdown show-select-search'
            });
            // 日期插件加载
            $('.form_date,.find_date').datetimepicker({
                language: 'zh-CN',
                format: 'yyyy-mm-dd',
                weekStart: 1,
                todayBtn: 1,
                autoclose: 1,
                todayHighlight: 1,
                startView: 2,
                minView: 2,
                forceParse: 0
            });
            $('.form_date').datetimepicker({}).on('hide', function (e) {
                $('.public_form').data('bootstrapValidator')
                    .updateStatus($(this).attr("name"), 'NOT_VALIDATED', null)
                    .validateField($(this).attr("name"));
            });
            $(".public_form").submit(function (ev) {
                ev.preventDefault();
            });

            $("#addbtn").on("click", function () {
                var that = this;
                var bootstrapValidator = $("#add_form").data('bootstrapValidator');
                bootstrapValidator.validate();
                if (bootstrapValidator.isValid()) {
                    $("#add_form")[0].submit();
                    $(this).attr("disabled", "true"); //设置变灰按钮  
                } else {
                    return;
                }
                setTimeout(function () {
                    $(that).removeAttr('disabled')
                }, 3000);
            })
            $("#savetn").on("click", function () {
                $(this).attr("disabled", "true"); //设置变灰按钮  
                var bootstrapValidator = $("#update_form").data('bootstrapValidator');
                bootstrapValidator.validate();
                if (bootstrapValidator.isValid()) {
                    $("#update_form")[0].submit();
                } else {
                    return;
                }
                setTimeout(function () {
                    $(that).removeAttr('disabled')
                }, 3000);
            })
            $('.modal').on('hidden.bs.modal', function (e) {
                $(".public_form")[0].reset();
                $(".public_form").data('bootstrapValidator').destroy();
                $('.public_form').data('bootstrapValidator', null);
                validator();
            })
            $(".updatebtn").on("click", function (e) {
                e.stopPropagation();
                var id = $(this).attr("data-id");
                $.ajax({
                    url: "{:U('edit')}",
                    type: 'GET', //GET
                    data: {
                        id: id
                    },
                    success: function (data) {
                        $("#update_form .form-control").each(function (index, val) {
                            var self = this;
                            for (x in data) {
                                if ($(self).attr("name") == x) {
                                    if ($(self)[0].tagName == "SELECT") {
                                        var $self = $(self).select2();
                                        $self.val(data[x]).trigger("change");
                                    } else if (x == "sids") {
                                        $(self).val(data[x]);
                                        $(self).tagsinput();
                                    } else {
                                        $(self).val(data[x]);
                                    }
                                }
                            }
                        });
                        //下拉框搜索插件加载
                        $('select[name="yw"]').select2({
                            dropdownCssClass: 'select-inverse-dropdown show-select-search'
                        });
                        $('select[name="xm"]').select2({
                            dropdownCssClass: 'select-inverse-dropdown show-select-search'
                        });
                        $('select[name="sy"]').select2({
                            dropdownCssClass: 'select-inverse-dropdown show-select-search'
                        });
                        // 重新更新日期选择器
                        $("#update_form .form_date").each(function (index, val) {
                            if ($(this).val() == "0000-00-00") {
                                $(this).val("")
                            }
                        })
                        $("#update_form .form_date").datetimepicker('update');
                    },
                    async: false,
                })
                $('#updateModal').modal();
            })
        })
    </script>
</block>